import React, {Component} from 'react';
import {StyleSheet, Text, View, Image, ScrollView, Alert, ImageBackground} from 'react-native';
import {Button, WhiteSpace, WingBlank, Flex, List, Provider, Toast, Radio, Modal, PickerView} from '@ant-design/react-native';

import {getOrderDataByParkingID, getParkingOrderInfo, setParkingOrderGiftState, createParkingPackageOrder} from '~/api/parking';
import {getPackageEdit, getPackageItemListApi, getParkingPackageInfo, createCompanyPackageOrder} from '~/api/order';
import {getHttpUrl} from '~/api/basic';
const RadioItem = Radio.RadioItem;
class PackageComfire extends Component {
    static navigationOptions = {
        title: '确认套餐订单',
    };
    constructor(props) {
        //调用基类的所有的初始化方法
        super(props);

        // 设置当前组件的属性
        this.state = {
            parkorderid: this.props.navigation.getParam('parkorderid'),
            list: [],
            packagelist: [],
            baseurl: '',
        };
        getHttpUrl().then((r) => {
            if (r.code === 0) {
                this.setState({
                    baseurl: r.data,
                });
            }
        });
        getParkingOrderInfo(this.state.parkorderid).then((r) => {
            if (r.code === 0) {
                //获取套餐信息
                this.getpackage(r.data.ParkingPackageID);
            } else {
                Alert.alert(r.msg);
            }
        });
        console.disableYellowBox = true;
    }
    getpackage(id) {
        getPackageEdit({
            order_id: id,
        }).then((r) => {
            if (r.code === 0) {
                getPackageItemListApi({
                    order_id: r.data.order.OrderDataID,
                }).then((r) => {
                    if (r.code === 0) {
                        this.setState({
                            packagelist: r.data.list,
                        });
                    } else {
                        Alert.alert(r.msg);
                    }
                });
                this.setState({
                    list: r.data.order,
                });
            } else {
                console.log(r.msg);
            }
        });
    }
    Comfiregift(ParkingOrderID) {
        Modal.alert('提示', '确认下单？', [
            {
                text: '取消',
            },
            {
                text: '确认',
                onPress: () => {
                    createCompanyPackageOrder({
                        parking_order_id: this.state.parkorderid,
                    }).then((r) => {
                        if (r.code === 0) {
                            this.props.navigation.replace('Packageupmoney', {orderid: r.data.id, parkorderid: this.state.parkorderid});
                        } else {
                            Toast.info(r.msg);
                        }
                    });
                },
            },
        ]);
    }
    render() {
        return (
            <View
                style={{
                    width: '100%',
                    height: '100%',
                    borderRadius: 10,
                    paddingTop: 10,
                }}>
                <ScrollView style={{marginBottom: 10}}>
                    <View
                        style={{
                            width: '100%',
                            height: 95,
                            marginTop: 10,
                            backgroundColor: 'white',
                            borderRadius: 10,
                        }}>
                        <Flex
                            // onPress={() => {
                            //     this.props.navigation.push('GiftList', {
                            //         params: this.state.list.OrderDataID,
                            //     });
                            // }}
                            style={{
                                width: '100%',
                            }}>
                            <View style={{padding: 10}}>
                                <Image
                                    style={{
                                        width: 75,
                                        height: 75,
                                    }}
                                    source={require('~/assets/public/demo2x.png')}
                                />
                            </View>
                            <Flex
                                style={{
                                    width: '80%',
                                    paddingLeft: 15,
                                    paddingRight: 15,
                                    marginTop: 20,
                                    marginBottom: 15,
                                }}
                                direction={'column'}
                                align={'start'}>
                                <Flex
                                    justify={'between'}
                                    style={{
                                        width: '100%',
                                        paddingRight: 10,
                                    }}>
                                    <Text
                                        numberOfLines={2}
                                        style={{
                                            fontSize: 15,
                                            fontWeight: 'bold',
                                            width: '50%',
                                        }}>
                                        {this.state.list.PackageName}
                                    </Text>
                                    <Flex style={{width: '50%'}} direction={'column'}>
                                        <Text
                                            numberOfLines={1}
                                            style={{
                                                fontSize: 15,
                                                fontWeight: 'bold',
                                                color: '#EC4F46',
                                            }}>
                                            原价:{this.state.list.PriceMarketTotal}元
                                        </Text>
                                        <Text
                                            numberOfLines={1}
                                            style={{
                                                fontSize: 15,
                                                fontWeight: 'bold',
                                                color: '#EC4F46',
                                            }}>
                                            采购价：{this.state.list.PriceFeeTotal}元
                                        </Text>
                                    </Flex>
                                </Flex>
                            </Flex>
                        </Flex>
                        <View style={styles.textfenge} />
                    </View>
                    {this.state.packagelist.map((item) => {
                        return (
                            <View
                                style={{
                                    marginTop: 10,
                                    backgroundColor: 'white',
                                    height: 95,
                                    padding: 10,
                                    borderRadius: 5,
                                    width: '100%',
                                }}>
                                <Flex>
                                    <Flex
                                        style={{width: '80%'}}
                                        onPress={() => {
                                            this.props.navigation.push('GiftInfo', {
                                                params: item.ProductDataID,
                                            });
                                        }}>
                                        <Image
                                            style={{
                                                width: '20%',
                                                height: 75,
                                                padding: 10,
                                                resizeMode: 'contain',
                                            }}
                                            source={{
                                                uri: this.state.baseurl + '/Product/' + item.ProductDataID + '/3/' + item.FileName,
                                            }}
                                        />
                                        <Flex direction="column" align="start" style={{padding: '3%', width: '80%'}}>
                                            <Text numberOfLines={1} style={{fontSize: 20}}>
                                                {item.ProductName}
                                            </Text>
                                            <Text
                                                style={{
                                                    paddingRight: 50,
                                                    fontSize: 20,
                                                    color: '#EC4F46',
                                                }}>
                                                {item.PriceMarketTotal}元
                                            </Text>
                                        </Flex>
                                    </Flex>
                                </Flex>
                            </View>
                        );
                    })}
                </ScrollView>
                <Flex
                    onPress={() => {
                        this.Comfiregift(this.state.parkorderid);
                    }}
                    style={{width: '100%', height: 50, backgroundColor: 'white', paddingTop: 8, paddingRight: 10}}
                    justify={'end'}
                    align={'start'}>
                    <ImageBackground style={{width: 94, height: 35}} source={require('~/assets/li/queding.png')}>
                        <Text style={{color: 'white', fontSize: 12, fontWeight: 'bold', textAlign: 'center', paddingTop: 10}}>确认下单</Text>
                    </ImageBackground>
                </Flex>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    textbuttom4: {
        fontSize: 12,
        width: 70,
        height: 25,
        borderRadius: 12,
        backgroundColor: '#FF3733',
        color: '#FFFFFF',
        textAlign: 'center',
        paddingTop: 4,
        marginLeft: 5,
    },
});
export default PackageComfire;
